package org.misalen.web.server.controllers.owner;

import org.misalen.annotations.ControllerApi;
import org.misalen.annotations.InterfaceApi;
import org.misalen.utils.TextUtil;
import org.misalen.web.database.model.mysql.pro.ProVideoInfo;
import org.misalen.web.database.model.mysql.pro.ProVideoReward;
import org.misalen.web.database.util.PaginationFrom;
import org.misalen.web.server.config.ServerUrl;
import org.misalen.web.server.controllers.BaseController;
import org.misalen.web.server.exception.CustomerException;
import org.misalen.web.server.forms.driver.DriverVideoDetailsForm;
import org.misalen.web.server.forms.user.VideoCompleteForm;
import org.misalen.web.server.forms.user.VideoPromoteForm;
import org.misalen.web.server.util.FormUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@ControllerApi(value = "视频广告", description = "", index = 300)
@RequestMapping(value = ServerUrl.OwnerVideoAdvertisingControllerUrl)
public class OwnerVideoAdvertisingController extends BaseController {

	@RequestMapping(value = "/promote", method = { RequestMethod.POST }, produces = "application/json")
	@InterfaceApi(value = "推广中", resultClass = { PaginationFrom.class, ProVideoInfo.class }, include = { "primaryKey",
			"videoName", "videoThumUrl", "startDate", "stopDate", "playedTime", "redEnvelopTotal" })
	public PaginationFrom<ProVideoInfo> promote(@RequestBody VideoPromoteForm form) throws CustomerException {
		FormUtil.validate(form);
		PaginationFrom<ProVideoInfo> pagination = formToPage(form, ProVideoInfo.class);
		return proVideoInfoRepository.findListByUser(form.getUserId(), TextUtil.booleanToString(true), pagination);
	}

	@RequestMapping(value = "/complete", method = { RequestMethod.POST }, produces = "application/json")
	@InterfaceApi(value = "已完成", resultClass = { PaginationFrom.class, ProVideoInfo.class }, include = { "primaryKey",
			"videoName", "videoThumUrl", "startDate", "stopDate", "playedTime", "redEnvelopTotal" })
	public PaginationFrom<ProVideoInfo> complete(@RequestBody VideoCompleteForm form) throws CustomerException {
		FormUtil.validate(form);
		PaginationFrom<ProVideoInfo> pagination = formToPage(form, ProVideoInfo.class);
		return proVideoInfoRepository.findListByUser(form.getUserId(), TextUtil.booleanToString(false), pagination);
	}
	
	@RequestMapping(value = "/details", method = { RequestMethod.POST }, produces = "application/json")
	@InterfaceApi(value = "详情", resultClass = { PaginationFrom.class, ProVideoReward.class }, include = { "getTime",
			"money", "userName" })
	public PaginationFrom<ProVideoReward> details(@RequestBody DriverVideoDetailsForm form) throws CustomerException {
		FormUtil.validate(form);
		return proVideoRewardRepository.getListByGet(form.getVideoId());
	}
}
